package com.leyou.item.controller;

import com.leyou.item.entity.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父id查询子分类列表
     */
    @GetMapping("/category/of/parent")
    public ResponseEntity<List<Category>> findCategoryByPid(@RequestParam("pid") Long pid){
        List<Category> categories = categoryService.findCategoryByPid(pid);
        return ResponseEntity.ok(categories);
    }

    /**
     * 根据分类id集合获取分类集合
     */
    @GetMapping("/category/list")
    public ResponseEntity<List<Category>> findCategoryByIds(@RequestParam("ids") List<Long> ids){
        List<Category> categoryList = categoryService.findCategoryByIds(ids);
        return ResponseEntity.ok(categoryList);
    }

}
